package leetcode;

/**
 * Created by Ghost on 2014/9/26 0026.
 */
public class Powx_N {
    public static double power(double x, int n){
        if(n==0)
            return 1;
        double rst = 1;
        double result = power(x,n/2);
        if((n & 1) !=0){
            rst = result * result * x;
        }
        else
            rst = result * result;
        return rst;
    }
    public static double pow(double x, int n){
        if(n>0)
            return power(x,n);
        else
            return 1/power(x,n);
    }
}
